<?php
namespace Home\Controller;
use Think\Controller;
class AliController extends Controller
{
    
    public function index()
    {   
        $num=$this->randString();
        //echo $num;
        $phone=trim(I('phone'));
        $c=Vendor('Alidayu.top.TopClient'); 
        $c=new \TopClient();
        $c->appkey =C('AlidayuAppKey');
        $c->secretKey =C('AlidayuAppSecret');
        //$req = new \Org\Util\AlibabaAliqinFcSmsNumSendRequest;
        $req=Vendor('Alidayu.top.request.AlibabaAliqinFcSmsNumSendRequest');
        $req=new \AlibabaAliqinFcSmsNumSendRequest();
        //$req->setExtend("123456");
        $req->setSmsType("normal");
        $req->setSmsFreeSignName("注册验证");
        $req->setSmsParam("{\"code\":\"$num\",\"product\":\"尚元优家Uchoice\"}");
        $req->setRecNum($phone);
        $req->setSmsTemplateCode("SMS_12200894");
        $resp = $c->execute($req);

        S($phone,$num,120);

    }
    /**
     * 获取随机位数数字
     * @param  integer $len 长度
     * @return string       
     */
    protected static function randString($len = 4)
    {
        $chars = str_repeat('0123456789', $len);
        $chars = str_shuffle($chars);
        $str   = substr($chars, 0, $len);
        return $str;
    }


    //验证短信验证
    public function check(){
        $num=I('num');
        $phone = I('phone');
        $verify = S($phone);
        if (empty($verify)) {
            exit('验证码失效');
        }

        if ($verify != $num) {
            exit('验证失败');
        }else{
            exit('验证成功');
        }


    }
}
?>
